package com.dubito.databindingtst

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.widget.doOnTextChanged
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.dubito.databindingtst.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var dataBinding: ActivityMainBinding
    private val user = User("jack", 26)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBinding =
            DataBindingUtil.setContentView(this, R.layout.activity_main)
        dataBinding.user = user
        dataBinding.presenter = Presenter()
    }

    inner class Presenter {

        fun onTextChanged(char: CharSequence, start: Int, before: Int, count: Int) {
            user.name = char.toString()
            dataBinding.user = user
        }

        fun onClick(view: View) {
            Toast.makeText(this@MainActivity, "点击了", Toast.LENGTH_SHORT).show()
        }

        fun onClickListenerBinding(user: User) {
            Toast.makeText(this@MainActivity, user.name, Toast.LENGTH_SHORT).show()
        }
    }
}
